﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：董辉
    //
    // 文件名：CompanyList_PS.cs
    // 文件功能描述：配送企业列表
    // 创建标识：董辉 2011-3-29 16:27
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Company
{
    public partial class CompanyList_PS : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
        IBLL_User iu = BLLFactory.BLL_User();
        KeyOperationLogJG kj; 
        public CompanyList_PS()
        {
            this.ModuleNo = Module.耗材配送汇总管理.ToString();
            this.PageOperateType = OperateType.配送企业列表.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (CurrentAccount.GetUser().Org.Area.AreaID != Constants.CURRENT_DEPLOY_AREAID)
                //{
                //    ddlCity.SelectedValue = CurrentAccount.GetUser().Org.Area.AreaID;
                //    ddlCity.Enabled = false;
                //}
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                //绑定地区数据
                //BindArea();
                //this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                //绑定列表数据
                //CompanyList_PS_DataBind();
            }
        }

        /// <summary>
        /// 绑定数据源方法
        /// 董辉
        /// 2011-3-29 16:26
        /// </summary>
        private void CompanyList_PS_DataBind()
        {
            int t = 0; 
            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog(); 
            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim()); 
            //if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            //{
            //    //hospro.AreaID = AreaControl1.SelectedAreaID;
            //    hospro.AreaID = ddlCity.SelectedValue;
            //}
            hospro.AreaID = ddlArea.SelectedAreaID;
            System.Data.DataTable dt = iEC.GetCompanyPS_ZongList(hospro, this.AspNetPager_CompanyList_PS.CurrentPageIndex, AspNetPager_CompanyList_PS.PageSize, out t); 
            AspNetPager_CompanyList_PS.RecordCount = t; 
            gvwPSLInfo.PageSize = AspNetPager_CompanyList_PS.PageSize; 
            this.gvwPSLInfo.DataSource = dt; 
            this.gvwPSLInfo.DataBind();
            AddLog(string.Format("查询配送企业列表高值数据!(配送企业列表)"));
        }

        /// <summary>
        /// 查询数据事件
        /// 董辉
        /// 2011-3-29 16:24
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager_CompanyList_PS.CurrentPageIndex = 1;
        }

        /// <summary>
        /// 导出数据事件
        /// 董辉
        /// 2011-3-29 16:27
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;

            HZ.Supervise.Model.View.HospitalProcureCatalog hospro = new HZ.Supervise.Model.View.HospitalProcureCatalog();

            hospro.CompanyName_PS = HZ.Supervise.DAL.DAL_Helper.Replace(txtCompanyPS.Text.ToString().Trim());

            //if (!string.IsNullOrEmpty(ddlCity.SelectedValue))
            //{
            //    //hospro.AreaID = AreaControl1.SelectedAreaID;
            //    hospro.AreaID = ddlCity.SelectedValue;
            //}
            hospro.AreaID = ddlArea.SelectedAreaID;
            System.Data.DataTable dt = iEC.GetCompanyPS_ZongList(hospro, 0, 0, out t);
            if (dt.Rows.Count > 0)
            {
                AddLog(string.Format("导出配送企业列表高值数据成功!(配送企业列表)"));
                ExportFile.Instance.ExportData(dt, gvwPSLInfo, this.Page);
            }
            else
            {
                HZ.Web.WebUtil.Alert("没有数据可导出!",this);
            }

        }

        /// <summary>
        /// 分页事件
        /// 董辉
        /// 2011-3-29 16:29
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void CompanyList_PS_PageChanged(object sender, EventArgs e)
        {
            CompanyList_PS_DataBind();
        }

        //#region 地区选择

        //public void BindArea()
        //{
        //    IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
        //    IList<Area> lstArea = new List<Area>();
        //    string userAreaId = CurrentAccount.GetUser().Org.Area.AreaID;
        //    //判断用户所属地区，如果用户是省级的 则可以列出全部区域
        //    if (userAreaId == CurrentAccount.GetCurrentDeployArea().AreaID)
        //    {
        //        lstArea = ia.GetSonAreas(userAreaId);
        //        foreach (Area area in lstArea)
        //        {
        //            if (area.AreaName == "省直属")
        //            {
        //                ListItem item = new ListItem();
        //                item.Text = area.AreaName;
        //                item.Value = area.AreaID;
        //                ddlCity.Items.Insert(0, item);
        //            }
        //            else
        //            {
        //                ListItem ddlitem = new ListItem();
        //                ddlitem.Text = area.AreaName;
        //                ddlitem.Value = area.AreaID;
        //                ddlCity.Items.Add(ddlitem);
        //            }
        //        }

        //        //ListItem a = new ListItem();
        //        //a.Text = "省直属";
        //        //a.Value = userAreaId;
        //        //ddlCity.Items.Insert(0, a);

        //        ListItem b = new ListItem();
        //        b.Text = "全部";
        //        b.Value = "";
        //        ddlCity.Items.Insert(0, b);
        //    }
        //    else
        //    {
        //        lstArea = ia.GetAreasByAreaID(userAreaId);
        //        foreach (Area area in lstArea)
        //        {
        //            ListItem ddlitem = new ListItem();
        //            ddlitem.Text = area.AreaName;
        //            ddlitem.Value = area.AreaID;
        //            ddlCity.Items.Add(ddlitem);
        //        }
        //    }
        //    //绑定数据源
        //    //如果有当前省的编号，则增加省直属 
        //    //同时地区获取值的要设置 

        //    //绑定区县
        //    ddlCity_SelectedIndexChanged(null, null);

        //}

        ///// <summary>
        ///// 地区编号
        ///// </summary>
        //public string AreaID
        //{
        //    get
        //    {
        //        if (!string.IsNullOrEmpty(ddlCountry.SelectedValue))
        //        {
        //            return ddlCountry.SelectedValue;
        //        }
        //        else
        //        {
        //            return ddlCity.SelectedValue;
        //        }
        //    }

        //    set
        //    {
        //        if (value != null)
        //        {
        //            if (value.Trim() == "")
        //            {
        //                ddlCity.SelectedIndex = 0;
        //            }
        //            else
        //            {
        //                string[] areaArray = value.ToString().Split(',');

        //                if (areaArray.Length > 1)
        //                {
        //                    ddlCity.SelectedIndex = 0;//多个地区的时候，显示全部
        //                }
        //                else
        //                {
        //                    for (int i = 0; i < ddlCity.Items.Count; i++)
        //                    {
        //                        if (ddlCity.Items[i].Value == value.Trim())
        //                        {
        //                            ddlCity.SelectedIndex = i;
        //                            break;
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}

        //protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    string strCity = (this.ddlCity.SelectedItem != null) ? this.ddlCity.SelectedItem.Value : "";

        //    this.ddlCountry.Items.Clear();

        //    IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
        //    IList<Area> lstArea = new List<Area>();
        //    if (!string.IsNullOrEmpty(strCity))
        //    {
        //        lstArea = ia.GetSonAreas(strCity);

        //        foreach (Area area in lstArea)
        //        {
        //            ListItem ddlitem = new ListItem();
        //            ddlitem.Text = area.AreaName;
        //            ddlitem.Value = area.AreaID;
        //            this.ddlCountry.Items.Add(ddlitem);
        //        }
        //    }

        //    ListItem b = new ListItem();
        //    b.Text = "所在区县";
        //    b.Value = "";
        //    ddlCountry.Items.Insert(0, b);
        //}

        //#endregion
        protected string GetBtnClientId()
        { 
            return this.btnQuery.ClientID; 
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="msg"></param>
        private void AddLog(string msg)
        {
            kj = new KeyOperationLogJG();
            kj.OperationLogSerialID = Guid.NewGuid().ToString();
            kj.Operator = CurrentAccount.GetUser().UserID;
            kj.OrgID = CurrentAccount.GetUser().Org.OrgID;
            kj.OperateTime = DateTime.Now;
            kj.OperateMessage = msg;
            iu.AddKeyOperationLog(kj);
        }
    }
}
